package cn.stazxr.component;

import java.awt.*;

/**
 * Package: cn.stazxr.component
 * FileDialogTest
 * @Author: stazxr
 * @Create: 2023/12/9
 * @Version: v1.0
 **/
public class FileDialogTest {
    public static void main(String[] args) {
        Frame frame = new Frame("Hello World");
        frame.setBounds(500, 500, 500, 300);
        frame.setAlwaysOnTop(true);

        FileDialog fileDialog = new FileDialog(frame, "FileDialog", FileDialog.LOAD);
        frame.addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent e) {
                fileDialog.setVisible(true);
                // 选择文件后，会返回文件的路径和文件名
                System.out.println(fileDialog.getDirectory() + fileDialog.getFile());
            }
        });

        frame.setVisible(true);
    }
}
